﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;

[Serializable]
public class Biology
{
    public enum EquipmentType{
        Normal,
        Up,
    }
    [Serializable]
    public class Dialogue {
        public string dialogueKey = "";
        public GMConfig.DialogueType type = GMConfig.DialogueType.Begin;
        public string audio = "";
        public Dialogue(){
            dialogueKey = "dialogue_" + Utils.GetTimeStamp(false).ToString();
        }
        public string GetStr()
        {
            return LTLocalization.GetText(dialogueKey);
        }
    }
    [Serializable]
    public class BiologyEquipment{
        public List<string> weaponList = new List<string>();
        public List<string> cardList = new List<string>();
    }
    //武器属性
    public string img = "";
    public string id = "";
    public string name = "";
    public string descript = "";
    private int levelUpLimit = 3;//等级上限
    public int blood = 0;
    public int defense = 0;
    public int attack = 0;

    public List<BiologyEquipment> biologyEquipmentList = new List<BiologyEquipment>();
    public List<Dialogue> dialogueList = new List<Dialogue>();

    public GMConfig.BiologyType type = GMConfig.BiologyType.Normal;

    public Biology()
    {
        var values = GetEquipmentEnumString();
        for(int i = 0;i < values.Length;i++){
            biologyEquipmentList.Add(new BiologyEquipment());
        }
    }
    /// <summary>
    /// 获得装备类型枚举内容
    /// </summary>
    /// <returns></returns>
    public string[] GetEquipmentEnumString(){
        EquipmentType e = new EquipmentType();
        string[] values = System.Enum.GetNames(e.GetType());
        return values;
    }
    /// <summary>
    /// 加入对白
    /// </summary>
    /// <param name="weaponId"></param>
    public int AddDialogue(){
        dialogueList.Add(new Dialogue());
        return dialogueList.Count - 1;
    }
    /// <summary>
    /// 从对白中移除
    /// </summary>
    /// <param name="weaponId"></param>
    public void RemoveDialogueAt(int index){
        dialogueList.RemoveAt(index);
    }
    /// <summary>
    /// 从对白中移除
    /// </summary>
    /// <param name="weaponId"></param>
    public void RemoveDialogue(Dialogue dialogue){
        if(!dialogueList.Contains(dialogue)) return;
        dialogueList.Remove(dialogue);
    }
    /// <summary>
    /// 加入武器
    /// </summary>
    /// <param name="weaponId"></param>
    public void AddWeapon(int type,string weaponId){
        if(biologyEquipmentList[(int)type].weaponList.Contains(weaponId)) return;
        biologyEquipmentList[(int)type].weaponList.Add(weaponId);
    }
    /// <summary>
    /// 从武器中移除
    /// </summary>
    /// <param name="weaponId"></param>
    public void RemoveWeapon(int type,string weaponId){
        if(!biologyEquipmentList[(int)type].weaponList.Contains(weaponId)) return;
        biologyEquipmentList[(int)type].weaponList.Remove(weaponId);
    }
    /// <summary>
    /// 加入卡牌
    /// </summary>
    /// <param name="weaponId"></param>
    public void AddCard(int type,string cardId){
        if(biologyEquipmentList[(int)type].cardList.Contains(cardId)) return;
        biologyEquipmentList[(int)type].cardList.Add(cardId);
    }
    /// <summary>
    /// 从卡牌中移除
    /// </summary>
    /// <param name="cardId"></param>
    public void RemoveCard(int type,string cardId){
        if(!biologyEquipmentList[(int)type].cardList.Contains(cardId)) return;
        biologyEquipmentList[(int)type].cardList.Remove(cardId);
    }
    public BiologyEquipment GetEquipment(int type){
        return biologyEquipmentList[(int)type];
    }
    /// <summary>
    /// 获得生物名称
    /// </summary>
    /// <returns></returns>
    public string GetBiologyName()
    {
        return LTLocalization.GetText(name);
    }
    /// <summary>
    /// 获得生物介绍
    /// </summary>
    /// <returns></returns>
    public string GetBiologyDescript()
    {
        return LTLocalization.GetText(descript);
    }
    /// <summary>
    /// 深拷贝
    /// 修改对象内容不会互相影响
    /// </summary>
    /// <returns></returns>
    public Biology DeepClone()
    {
        using (Stream objectStream = new MemoryStream())
        {
            IFormatter formatter = new BinaryFormatter();
            formatter.Serialize(objectStream,this);
            objectStream.Seek(0, SeekOrigin.Begin);
            return formatter.Deserialize(objectStream) as Biology;
        }
    }
}

